#!/bin/sh
# This regression test is a part of SIPp.
# Message texts: a failed RTP check names the pattern that failed (it
# used to print the bit mask of the failed ids as a count of errors),
# and a warning leaves no blank line in the error file (some ended with
# a newline of their own).
. "`dirname "$0"`/../functions"; init

dir=`mktemp -d`
trap 'rm -rf "$dir"' EXIT

# A UAS without -rtp_echo: pattern 3, which the UAC plays, never comes
# back. Its bit in the mask is 4.
sippbg -sn uas -i 127.0.0.1 -p 23140 -m 1 \
    -min_rtp_port 23700 -max_rtp_port 23799
sippfg -sf rtp.xml -i 127.0.0.1 -p 23141 -m 1 -d 1000 \
    -min_rtp_port 23800 -max_rtp_port 23899 -audiotolerance 0.2 \
    127.0.0.1:23140 -timeout 10 >/dev/null 2>"$dir/stderr"
status=$?
test $status -eq 253 || fail "RTP check: exit code $status"
grep -q 'RTP check failed: pattern 3$' "$dir/stderr" ||
    fail "`grep 'RTP check' "$dir/stderr"`"

# The UAS warns of the ACK's CSeq.
sippbg -sn uas -i 127.0.0.1 -p 23142 -m 1 -trace_err \
    -error_file "$dir/errors"
sippfg -sf ack.xml -i 127.0.0.1 -p 23143 -m 1 127.0.0.1:23142 \
    -timeout 10 >/dev/null 2>&1
status=$?
test $status -eq 0 || fail "ACK: exit code $status"
for i in 1 2 3 4 5 6 7 8 9 10; do
    grep -q 'ACK CSeq value does NOT match' "$dir/errors" 2>/dev/null && break
    test $i -eq 10 && fail "no ACK CSeq warning"
    sleep 0.5
done
grep -q '^$' "$dir/errors" && fail "a blank line in the error file"
ok
